﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace Business.Models
{
    public class LopHoc
    {
        [Key]
        public int IdLopHoc { get; set; }
        public string TenLop { get; set; }
        public int IdNienHoc { get; set; }
        [ForeignKey("IdNienHoc")] 
        public virtual NienHoc NienHoc { get; set; }
        public int KhoiLopHienTai { get; set; }
        [ForeignKey("KhoiLopHienTai")]
        public virtual KhoiLop KhoiLop { get; set; }
        public bool HoatDong { get; set; }
        public int IdNhanVien { get; set; }
        [ForeignKey("IdNhanVien")] 
        public virtual QuanTri QuanTri { get; set; }
    }

    public class LopHocConfiguration : EntityTypeConfiguration<LopHoc>
    {

        public LopHocConfiguration()
            : base()
        {

            HasKey(d => d.IdLopHoc);
            Property(d => d.IdLopHoc).
                HasColumnName("IdLopHoc").
                HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).
                IsRequired();
            Property(x => x.IdNienHoc).HasColumnName("NienHoc");
            Property(d => d.TenLop).
                HasColumnName("TenLop").
                IsRequired();
            HasRequired(x => x.NienHoc).
            WithMany().
                Map(x => x.MapKey("NienHoc"));
            HasRequired(x => x.KhoiLop).
            WithMany().
                Map(x => x.MapKey("KhoiLopHienTai"));
            Property(d => d.HoatDong).
                HasColumnName("HoatDong").
                IsRequired();

            HasRequired(x => x.QuanTri).
            WithMany().
                Map(x => x.MapKey("IdNhanVien"));
            ToTable("LopHoc", "dbo");
        }

    }
}